/**
 * 手牌吃碰杠控件
 */
class Peng extends how.module.View {
	public tag: string = "";
	public bg_3: eui.Image;
	public card_0: eui.Image;
	public card_1: eui.Image;
	public card_2: eui.Image;
	public card_3: eui.Image;

	public arr: eui.Image;

	public constructor() {
		super();
	}

	public childrenCreated(): void { }

	public setData(d: PengItem): void {
		this.visible = true;
		this.bg_3.visible = true;
		if (d.data.length == 3) {
			this.card_3.visible = false;
			this.bg_3.visible = false;
		}
		for (let i = 0; i < d.data.length; i++) {
			(this["card_" + i] as eui.Image).visible = true;
			if (d.type == MjLogic.Prio.Gang) {
				(this["card_" + i] as eui.Image).visible = false;
				(((this["card_" + i] as eui.Image).parent as eui.Group).getChildAt(0) as eui.Image).source = "mj_card_" + 999 + "_png";
			} else {
				(((this["card_" + i] as eui.Image).parent as eui.Group).getChildAt(0) as eui.Image).source = "mj_udt_png";
				(this["card_" + i] as eui.Image).source = "mj_card_" + d.data[i] + "_png";
			}
		}
		if (this.tag == "mp" && d.type == MjLogic.Prio.Gang) {	//暗杠将自己最上面的牌显示
			this.card_3.source = "mj_card_" + d.data[0] + "_png";
			this.bg_3.source = "mj_udt_png";
			this.card_3.visible = true;
			this.bg_3.visible = true;
		}
		switch (d.type) {
			case MjLogic.Prio.ChiLeft:
				base.Utils.dark(this["card_" + 0].parent);
				break;
			case MjLogic.Prio.ChiMiddle:
				base.Utils.dark(this["card_" + 1].parent);
				break;
			case MjLogic.Prio.ChiRight:
				base.Utils.dark(this["card_" + 2].parent);
				break
		}
		//如果是吃碰杠，则显示箭头
		let pv:MJPlayerView = <MJPlayerView>D.App.gameView.playerList[0];
		if (d.type == MjLogic.Prio.ChiLeft || d.type == MjLogic.Prio.Peng || d.type == MjLogic.Prio.Gang || d.type == MjLogic.Prio.ChiMiddle || d.type == MjLogic.Prio.ChiRight) {
			this.arr.source = "mj_arr" + MjLogic.getSeatID(d.takeUser, pv.chairId) + "_png";
			this.arr.visible = true;
		} else {
			this.arr.visible = false;
		}
	}

	public setBuGang(): void {
		this.card_3.visible = true;
		this.bg_3.visible = true;
		this.bg_3.source = "mj_udt_png";
		this.card_3.source = this.card_0.source;
	}

	public clear(): void {
		this.card_0.source = this.card_1.source = this.card_2.source = this.card_3.source = "";
		this.visible = false
		for (var i = 0; i < 4; i++) {
			(this["card_" + i].parent as eui.Group).filters = null;
			(((this["card_" + i] as eui.Image).parent as eui.Group).getChildAt(0) as eui.Image).visible = true;
		}
	}
}